<template>
  <div class="tabcontrol">
    <div
      v-for="(itme, index) in titles"
      class="tbacontrolitme"
      :class="{ active: index == currentIndex }"
      @click="itmeclick(index)"
    >
      <samp>{{ itme }}</samp>
    </div>
  </div>
</template>

<script>
export default {
  name: "tabcontrol",
  props: {
    titles: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      currentIndex: 0,
    };
  },
  methods: {
    itmeclick(index) {
      // console.log("点击了");
      this.currentIndex = index; //监听点击来改变字体颜色
      this.$emit("tabbarclick", index); //在定义事件 当子组件点击事件
    },
  },
};
</script>

<style>
.tabcontrol {
  display: flex;
  text-align: center;
  background-color: rgb(126, 163, 241);
  z-index: 6;
}
.tbacontrolitme {
  flex: 1;
  height: 40px;
  line-height: 40px;
  font-size: 16px;
  /* border-bottom: 1px solid red; */
}
.tbacontrolitme samp {
  padding-bottom: 5px;
}
.active {
  color: red;
}
.active samp {
  border-bottom: 1px solid red;
}
</style>